home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue51 / Remote / CliePull.dpr < prev    next >
Encoding:
Text File  |  1999-09-22  |  1.5 KB  |  57 lines

  1. program CliePull;
  2. {$APPTYPE CONSOLE}
  3. uses
  4.   SysUtils, Windows, Classes, Graphics, JPEG;
  5.  
  6. const
  7.   Head: array[0..26] of char = 'content-type: image/jpg'#13#10#13#10;
  8. var
  9.   hForeignWin: THandle;
  10.   wDC: HDC;
  11.   SrcRect: TRect;
  12.   Bitmap: TBitmap;
  13.   AStream: TMemoryStream;
  14.   Buffer: array[0..8191] of Byte;
  15.   BytesToSend: Integer;
  16. begin
  17.   Rewrite(Output);
  18.   FileWrite(TTextRec(Output).Handle, Head, SizeOf(Head));
  19.  
  20.   Bitmap := TBitmap.Create;
  21.   with Bitmap do
  22.   try
  23.     hForeignWin := FindWindow('System Monitor', 'System Monitor');
  24.     try
  25.       SetForegroundWindow(hForeignWin);
  26.       RedrawWindow(hForeignWin, nil, 0, RDW_INVALIDATE+RDW_UPDATENOW);
  27.       GetWindowRect(hForeignWin, SrcRect);
  28.       Width := SrcRect.Right-SrcRect.Left;
  29.       Height := SrcRect.Bottom-SrcRect.Top;
  30.       wDC := GetWindowDC(hForeignWin);
  31.       BitBlt(Canvas.Handle, 0, 0, Width, Height, wDC, 0, 0, SRCCOPY);
  32.       with TJPEGImage.Create do
  33.       try
  34.         Assign(Bitmap);
  35.         AStream := TMemoryStream.Create;
  36.         try
  37.           SaveToStream(AStream);
  38.           AStream.Seek(soFromBeginning, 0);
  39.           while AStream.Position < AStream.Size do
  40.           begin
  41.             BytesToSend := AStream.Read(Buffer, SizeOf(Buffer));
  42.             FileWrite(TTextRec(Output).Handle, Buffer, BytesToSend);
  43.           end;
  44.         finally
  45.           AStream.Free;
  46.         end;
  47.       finally
  48.         Free;
  49.       end;
  50.     finally
  51.       ReleaseDC(hForeignWin, wDC);
  52.     end;
  53.   finally
  54.     Bitmap.Free;
  55.   end;
  56. end.
  57.